/* Sidebar 主容器 */
.sidebar {
  display: flex;
  flex-direction: column;
  background: var(--color-sidebar-bg);
  border-right: 1px solid var(--color-sidebar-border);
  height: 100%;
  z-index: 100;
  transition: all var(--transition-normal);
  box-shadow: var(--shadow-sm);
}

/* 桌面端样式 */
.sidebar.desktop {
  position: relative;
  width: 280px;
  min-width: 200px;
  max-width: 400px;
  flex-shrink: 0;
}

.sidebar.desktop.closed {
  width: 40px;
  min-width: 40px;
  overflow: hidden;
  border-right: 1px solid var(--color-border-primary);
}

.sidebar.desktop.closed .header {
  padding: 4px;
  border-bottom: none;
  justify-content: center;
  min-height: 32px;
}

.sidebar.desktop.closed .headerActions {
  flex-direction: column;
  gap: 2px;
}

.sidebar.desktop.closed .title {
  display: none;
}

.sidebar.desktop.closed .content {
  display: none;
}

.sidebar.desktop.closed .resizeHandle {
  display: none;
}

.sidebar.desktop.open {
  width: 280px;
}

/* 移动端样式 */
.sidebar.mobile {
  position: fixed;
  top: 0;
  left: 0;
  width: 280px;
  max-width: 80vw;
  height: 100vh;
  z-index: 1000;
  border-right: none;
  box-shadow: 2px 0 15px rgba(0, 0, 0, 0.2);
}

.sidebar.mobile.closed {
  transform: translateX(-100%);
  box-shadow: none;
}

.sidebar.mobile.open {
  transform: translateX(0);
}

/* 头部样式 */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 12px;
  border-bottom: 1px solid var(--color-sidebar-border);
  background: var(--color-bg-primary);
  min-height: 32px;
  user-select: none;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.03);
}

.title {
  display: flex;
  align-items: center;
  margin: 0;
  font-size: 13px;
  font-weight: 500;
  color: var(--color-text-secondary);
  flex: 1;
  letter-spacing: 0.01em;
}

.titleIcon {
  margin-right: 8px;
  opacity: 0.8;
  flex-shrink: 0;
  color: var(--color-primary);
}

.titleText {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.headerActions {
  display: flex;
  align-items: center;
  gap: 4px;
}

.newFileButton,
.newFolderButton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  border-radius: var(--border-radius-sm);
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  flex-shrink: 0;
}

.newFileButton:hover,
.newFolderButton:hover {
  background: var(--color-bg-hover);
  color: var(--color-primary);
}

.newFileButton:focus-visible,
.newFolderButton:focus-visible {
  background: var(--color-bg-hover);
  box-shadow: 0 0 0 2px var(--color-primary-alpha);
}

.toggleButton {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  background: transparent;
  border: none;
  border-radius: var(--border-radius-sm);
  color: var(--color-text-tertiary);
  cursor: pointer;
  transition: all var(--transition-fast);
  outline: none;
  flex-shrink: 0;
}

.toggleButton:hover {
  background: var(--color-bg-hover);
  color: var(--color-primary);
}

.toggleButton:focus-visible {
  background: var(--color-bg-hover);
  box-shadow: 0 0 0 2px var(--color-primary-alpha);
}

/* 收起状态的展开按钮样式 */
.sidebar.desktop.closed .toggleButton {
  color: var(--color-primary);
  background: var(--color-primary-bg);
}

.sidebar.desktop.closed .toggleButton:hover {
  background: var(--color-primary);
  color: white;
}

.toggleIcon {
  transition: transform var(--transition-fast);
}

/* 内容区域 */
.content {
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* 拖拽调整大小的手柄 */
.resizeHandle {
  position: absolute;
  top: 0;
  right: -3px;
  width: 6px;
  height: 100%;
  cursor: col-resize;
  background: transparent;
  z-index: 10;
  transition: background var(--transition-fast);
}

.resizeHandle:hover {
  background: var(--color-primary-alpha);
}

.resizeHandle::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 40px;
  background: var(--color-border-secondary);
  border-radius: 1px;
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.resizeHandle:hover::after {
  opacity: 1;
}


/* 移动端背景遮罩 */
.backdrop {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 999;
  animation: fadeIn 0.2s ease-out;
  backdrop-filter: blur(2px);
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* 移动端适配 */
@media (max-width: 768px) {
  .sidebar.mobile {
    width: 300px;
    max-width: 85vw;
  }
  
  .header {
    padding: 4px 8px;
    min-height: 26px;
  }
  
  .title {
    font-size: 11px;
    font-weight: 400;
  }
  
  .titleIcon {
    margin-right: 4px;
  }
  
  .toggleButton {
    width: 22px;
    height: 22px;
  }
}

@media (max-width: 480px) {
  .sidebar.mobile {
    width: 280px;
    max-width: 90vw;
  }
  
  .header {
    padding: 3px 6px;
    min-height: 22px;
  }
  
  .title {
    font-size: 10px;
  }
  
  .titleIcon {
    margin-right: 3px;
  }
  
  .toggleButton {
    width: 18px;
    height: 18px;
  }
  
}

/* 暗色主题适配 */
@media (prefers-color-scheme: dark) {
  .sidebar {
    box-shadow: 0 0 20px rgba(0, 0, 0, 0.3);
  }
  
  .sidebar.mobile {
    box-shadow: 2px 0 15px rgba(0, 0, 0, 0.4);
  }
  
  
  .backdrop {
    background: rgba(0, 0, 0, 0.7);
  }
}

/* 高对比度模式 */
@media (prefers-contrast: high) {
  .sidebar {
    border-right: 2px solid var(--color-border-primary);
  }
  
  .header {
    border-bottom: 2px solid var(--color-border-primary);
  }
  
  .toggleButton:focus-visible {
    box-shadow: 0 0 0 3px var(--color-primary);
  }
}


/* 减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  .sidebar,
  .toggleButton,
  .toggleIcon,
  .resizeHandle,
  .backdrop {
    transition: none;
    animation: none;
  }
}
